package com.hbk.base.util;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

public class PageUtil {

    public static String fromClient(){
        HttpServletRequest request =
                ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        String header = request.getHeader("user-agent");
        if(StringUtil.isEmpty(header)){
            return "/pc";
        }
        String upHead = header.toUpperCase();
        List<String> tagList = new ArrayList<>();
        tagList.add("ios");
        tagList.add("android");
        tagList.add("MicroMessenger");
//        tagList.add("AppleWebKit");
        tagList.add("WeChat");
        tagList.add("iphone");
        tagList.add("ipad");
        boolean result = true;
        for(String tag : tagList){
            String upTag = tag.toUpperCase();
            if(upHead.contains(upTag)){
                result = false;
                break;
            }
        }
        if(result){
            return "/pc";
        }
        return "/mobile";
    }
}
